package com.weisha.bledemo.retrofit;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.weisha.bledemo.application.App;

import okhttp3.MultipartBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;


/**
 * 公共网络请求类 Created by 房杰 on 2016/7/23.
 */
public class CommonOkHttp {
    private static Gson gson;
    public static String baseUrl = "http://114.55.31.10:8384/";
    public static Gson buildGson() {
        if (gson == null) {
            gson = new GsonBuilder()
                    .setDateFormat("yyyy-MM-dd HH:mm:ss")
                    .create();
        }
        return gson;
    }

    // 创建retrofit实体
    public static Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(baseUrl)
            .client(App.getClient())
            .addConverterFactory(GsonConverterFactory.create(buildGson()))
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .build();

    // 创建ApiService实体
    public static ApiService apiService = retrofit.create(ApiService.class);

    /**
     * 获取密码
     * @param callback
     */
    public static void toGetPSWD(Callback<ResponseBody> callback) {
        Call<ResponseBody> call = apiService.getpswd();
        call.enqueue(callback);
    }

    /**
     * 获取设备是否可用
     * @param id
     * @param callback
     */
    public static void toGetDevice(String id, Callback<BaseCommonResponse> callback){
        Call<BaseCommonResponse> call = apiService.getDevice(id);
        call.enqueue(callback);
    }


}